package npda;

import dpda.DPDADesign;
import dpda.DPDARulebook;
import org.junit.jupiter.api.Test;
import pda.PDAConfiguration;
import pda.PDARule;
import pda.Stack;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author haoly
 * @title NPDATest
 * @date 2025/4/22 09:49
 * @description TODO
 */
public class NPDATest {
    @Test
    public void testAccepting() {
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, 'a', 1, '$', "a$"),
                new PDARule<>(1, 'a', 1, 'a', "aa"),
                new PDARule<>(1, 'a', 1, 'b', "ab"),
                new PDARule<>(1, 'b', 1, '$', "b$"),
                new PDARule<>(1, 'b', 1, 'b', "bb"),
                new PDARule<>(1, 'b', 1, 'a', "ba"),
                new PDARule<>(1, null, 2, '$', "$"),
                new PDARule<>(1, null, 2, 'a', "a"),
                new PDARule<>(1, null, 2, 'b', "b"),
                new PDARule<>(2, 'a', 2, 'a', ""),
                new PDARule<>(2, 'b', 2, 'b', ""),
                new PDARule<>(2, null, 3, '$', "$")
        );
        NPDARulebook<Integer> rulebook = new NPDARulebook<>(rules);

        Stack<Character> stack = new Stack<>(Arrays.asList('$'));

        PDAConfiguration<Integer> configuration = new PDAConfiguration<>(1, stack);

        System.out.println(configuration);

        NPDA<Integer> npda = new NPDA<>(Set.of(configuration), Set.of(3), rulebook);
        assertTrue(npda.accepting());
        System.out.println(npda.getCurrentConfigurations());

        npda.readString("abb");
        assertFalse(npda.accepting());
        System.out.println(npda.getCurrentConfigurations());

        npda.readString("a");
        assertTrue(npda.accepting());
        System.out.println(npda.getCurrentConfigurations());


    }
}
